package org.gpf.service;

import java.util.List;

import org.gpf.dao.ArticleDetailDAO;
import org.gpf.dao.ArticleOutlineDAO;
import org.gpf.dao.impl.ArticleDetailDAOImpl;
import org.gpf.dao.impl.ArticleOutlineDAOImpl;
import org.gpf.po.ArticleDetail;
import org.gpf.po.ArticleOutline;
import org.gpf.util.IConst;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

/**
 * 
* @ClassName: DataService 
* @Description: 处理Servlet
* @author gaopengfei
* @date 2015-9-29 下午1:31:41 
*
 */
public class QueryService {

	/**
	 * 得到文章概要的json数组
	 */
	public String getArticleOutlineJsonArry(String page){
		
		ArticleOutlineDAO articleOutlineDAO = new ArticleOutlineDAOImpl();
		String jsonArrayStr = null;
		try {
			List<ArticleOutline> articleOutlines = articleOutlineDAO.queryArticleOutlines(Integer.parseInt(page), IConst.PAGE_SIZE);
			jsonArrayStr = JSONArray.toJSONString(articleOutlines);
		} catch (Exception e) {
			jsonArrayStr = IConst.ERROR;
		}
		return jsonArrayStr;
	}
	
	/**
	 * 得到文章详情的json对象
	 * @return
	 */
	public String getArticleDetailJsonObj(String id){
		
		ArticleDetailDAO articleDetailDAO = new ArticleDetailDAOImpl();
		String jsonStr = null;
		try {
			ArticleDetail articleDetail = articleDetailDAO.queryArticleDetails(Integer.parseInt(id));
			jsonStr = JSON.toJSONString(articleDetail);
		} catch (Exception e) {
			jsonStr = IConst.ERROR;
		}
		return jsonStr;
	}
}
